﻿// Decompiled with JetBrains decompiler
// Type: 我的小工具.sqlserverDB
// Assembly: 开发辅助工具, Version=1.0.0.1, Culture=neutral, PublicKeyToken=null
// MVID: F78E5980-5E94-4E46-ABDF-DC8C6CBF52AA
// Assembly location: K:\Tools\工具\开发辅助工具庆六一版\开发辅助工具2015-06-01\开发辅助工具.exe

using PetaPoco;
using System;
using System.Collections.Generic;

namespace 我的小工具
{
  public class sqlserverDB : Database
  {
    [ThreadStatic]
    private static sqlserverDB _instance;

    public static sqlserverDB.IFactory Factory { get; set; }

    public sqlserverDB()
      : base("sqlserver")
    {
    }

    public sqlserverDB(string connectionStringName)
      : base(connectionStringName)
    {
    }

    public static sqlserverDB GetInstance()
    {
      if (sqlserverDB._instance != null)
        return sqlserverDB._instance;
      if (sqlserverDB.Factory != null)
        return sqlserverDB.Factory.GetInstance();
      return new sqlserverDB();
    }

    public override void OnBeginTransaction()
    {
      if (sqlserverDB._instance != null)
        return;
      sqlserverDB._instance = this;
    }

    public override void OnEndTransaction()
    {
      if (sqlserverDB._instance != this)
        return;
      sqlserverDB._instance = (sqlserverDB) null;
    }

    public interface IFactory
    {
      sqlserverDB GetInstance();
    }

    public class Record<T> where T : new()
    {
      public static sqlserverDB repo
      {
        get
        {
          return sqlserverDB.GetInstance();
        }
      }

      public bool IsNew()
      {
        return sqlserverDB.Record<T>.repo.IsNew((object) this);
      }

      public object Insert()
      {
        return sqlserverDB.Record<T>.repo.Insert((object) this);
      }

      public void Save()
      {
        sqlserverDB.Record<T>.repo.Save((object) this);
      }

      public int Update()
      {
        return sqlserverDB.Record<T>.repo.Update((object) this);
      }

      public int Update(IEnumerable<string> columns)
      {
        return sqlserverDB.Record<T>.repo.Update((object) this, columns);
      }

      public static int Update(string sql, params object[] args)
      {
        return sqlserverDB.Record<T>.repo.Update<T>(sql, args);
      }

      public static int Update(Sql sql)
      {
        return sqlserverDB.Record<T>.repo.Update<T>(sql);
      }

      public int Delete()
      {
        return sqlserverDB.Record<T>.repo.Delete((object) this);
      }

      public static int Delete(string sql, params object[] args)
      {
        return sqlserverDB.Record<T>.repo.Delete<T>(sql, args);
      }

      public static int Delete(Sql sql)
      {
        return sqlserverDB.Record<T>.repo.Delete<T>(sql);
      }

      public static int Delete(object primaryKey)
      {
        return sqlserverDB.Record<T>.repo.Delete<T>(primaryKey);
      }

      public static bool Exists(object primaryKey)
      {
        return sqlserverDB.Record<T>.repo.Exists<T>(primaryKey);
      }

      public static T SingleOrDefault(object primaryKey)
      {
        return sqlserverDB.Record<T>.repo.SingleOrDefault<T>(primaryKey);
      }

      public static T SingleOrDefault(string sql, params object[] args)
      {
        return sqlserverDB.Record<T>.repo.SingleOrDefault<T>(sql, args);
      }

      public static T SingleOrDefault(Sql sql)
      {
        return sqlserverDB.Record<T>.repo.SingleOrDefault<T>(sql);
      }

      public static T FirstOrDefault(string sql, params object[] args)
      {
        return sqlserverDB.Record<T>.repo.FirstOrDefault<T>(sql, args);
      }

      public static T FirstOrDefault(Sql sql)
      {
        return sqlserverDB.Record<T>.repo.FirstOrDefault<T>(sql);
      }

      public static T Single(object primaryKey)
      {
        return sqlserverDB.Record<T>.repo.Single<T>(primaryKey);
      }

      public static T Single(string sql, params object[] args)
      {
        return sqlserverDB.Record<T>.repo.Single<T>(sql, args);
      }

      public static T Single(Sql sql)
      {
        return sqlserverDB.Record<T>.repo.Single<T>(sql);
      }

      public static T First(string sql, params object[] args)
      {
        return sqlserverDB.Record<T>.repo.First<T>(sql, args);
      }

      public static T First(Sql sql)
      {
        return sqlserverDB.Record<T>.repo.First<T>(sql);
      }

      public static List<T> Fetch(string sql, params object[] args)
      {
        return sqlserverDB.Record<T>.repo.Fetch<T>(sql, args);
      }

      public static List<T> Fetch(Sql sql)
      {
        return sqlserverDB.Record<T>.repo.Fetch<T>(sql);
      }

      public static List<T> Fetch(long page, long itemsPerPage, string sql, params object[] args)
      {
        return sqlserverDB.Record<T>.repo.Fetch<T>(page, itemsPerPage, sql, args);
      }

      public static List<T> Fetch(long page, long itemsPerPage, Sql sql)
      {
        return sqlserverDB.Record<T>.repo.Fetch<T>(page, itemsPerPage, sql);
      }

      public static List<T> SkipTake(long skip, long take, string sql, params object[] args)
      {
        return sqlserverDB.Record<T>.repo.SkipTake<T>(skip, take, sql, args);
      }

      public static List<T> SkipTake(long skip, long take, Sql sql)
      {
        return sqlserverDB.Record<T>.repo.SkipTake<T>(skip, take, sql);
      }

      public static Page<T> Page(long page, long itemsPerPage, string sql, params object[] args)
      {
        return sqlserverDB.Record<T>.repo.Page<T>(page, itemsPerPage, sql, args);
      }

      public static Page<T> Page(long page, long itemsPerPage, Sql sql)
      {
        return sqlserverDB.Record<T>.repo.Page<T>(page, itemsPerPage, sql);
      }

      public static IEnumerable<T> Query(string sql, params object[] args)
      {
        return sqlserverDB.Record<T>.repo.Query<T>(sql, args);
      }

      public static IEnumerable<T> Query(Sql sql)
      {
        return sqlserverDB.Record<T>.repo.Query<T>(sql);
      }
    }
  }
}
